package com.ruoyi.web.controller.agriculture;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.agriculture.domain.po.AgInput;
import com.ruoyi.system.agriculture.service.IAgInputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 农业投入品Controller
 */
@RestController
@RequestMapping("/agriculture/input")
public class AgInputController extends BaseController {
    @Autowired
    private IAgInputService inputService;

    /**
     * 查询农业投入品列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:input:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgInput input) {
        startPage();
        List<AgInput> list = inputService.selectInputList(input);
        return getDataTable(list);
    }

    /**
     * 导出农业投入品列表
     */
    @PreAuthorize("@ss.hasPermi('agriculture:input:export')")
    @Log(title = "农业投入品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AgInput input) {
        List<AgInput> list = inputService.selectInputList(input);
        ExcelUtil<AgInput> util = new ExcelUtil<>(AgInput.class);
        return util.exportExcel(list, "农业投入品数据");
    }

    /**
     * 获取农业投入品详细信息
     */
    @PreAuthorize("@ss.hasPermi('agriculture:input:query')")
    @GetMapping(value = "/{inputId}")
    public AjaxResult getInfo(@PathVariable("inputId") Long inputId) {
        return success(inputService.getById(inputId));
    }

    /**
     * 新增农业投入品
     */
    @PreAuthorize("@ss.hasPermi('agriculture:input:add')")
    @Log(title = "农业投入品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgInput input) {
        return toAjax(inputService.save(input));
    }

    /**
     * 修改农业投入品
     */
    @PreAuthorize("@ss.hasPermi('agriculture:input:edit')")
    @Log(title = "农业投入品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgInput input) {
        return toAjax(inputService.updateById(input));
    }

    /**
     * 删除农业投入品
     */
    @PreAuthorize("@ss.hasPermi('agriculture:input:remove')")
    @Log(title = "农业投入品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{inputIds}")
    public AjaxResult remove(@PathVariable Long[] inputIds) {
        return toAjax(inputService.removeBatchByIds(List.of(inputIds)));
    }
} 